package com.lagou;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

/**
 * @author 司晨雨
 * @date 2020/11/1 20:37
 * @description
 */
@Activate(group = CommonConstants.CONSUMER)
public class TransportIPFilter implements Filter {

    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        String ip = invoker.getUrl().getIp();
        String port = String.valueOf(invoker.getUrl().getPort());
        String ipPort = ip + ":" + port;
        RpcContext.getContext().setAttachment("ip", ipPort);
        System.out.println("请求的IP地址为：" + ip);
        Result result = invoker.invoke(invocation);
        return result;
    }
}
